package com.BaoHua.demo.aop;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Component
public class WebAspect {

	@Pointcut("execution(public * com.BaoHua.demo.web.*.*(..))")
	public void webLog() {
		
	}
	
	@Before("webLog()")
	public void before(JoinPoint joinPoint) throws Throwable{
		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = attributes.getRequest();
		System.out.println("URL: "+request.getRequestURL());
		System.out.println("URI: "+request.getRequestURI());
		System.out.println("方法: "+request.getMethod());
		System.out.println("IP: "+request.getRemoteAddr());
		
	}
	
}
